import xml.etree.ElementTree as et
import os

def toxml(
        p_folder,
        p_filename,
        p_width,
        p_height,
        p_depth,
        p_name,
        p_xmin,
        p_xmax,
        p_ymin,
        p_ymax,
        p_truncated,
        p_difficult,
        p_segmented
):
    etree = et.ElementTree()

    annotation = et.Element('annotation')
    etree._setroot(annotation)

    folder = et.SubElement(annotation, 'folder')
    folder.text = p_folder

    filename = et.SubElement(annotation, 'filename')
    filename.text = p_filename

    size = et.SubElement(annotation, 'size')
    width = et.SubElement(size, 'width')
    width.text = p_width
    height = et.SubElement(size, 'height')
    height.text = p_height
    depth = et.SubElement(size, 'depth')
    depth.text = p_depth

    obj = et.SubElement(annotation, 'object')
    name = et.SubElement(obj, 'name')
    name.text = p_name

    bndbox = et.SubElement(obj, 'bndbox')
    xmin = et.SubElement(bndbox, 'xmin')
    xmin.text = p_xmin
    xmax = et.SubElement(bndbox, 'xmax')
    xmax.text = p_xmax
    ymin = et.SubElement(bndbox, 'ymin')
    ymin.text = p_ymin
    ymax = et.SubElement(bndbox, 'ymax')
    ymax.text = p_ymax

    truncated = et.SubElement(obj, 'truncated')
    truncated.text = p_truncated

    difficult = et.SubElement(obj, 'difficult')
    difficult.text = p_difficult

    segmented = et.SubElement(annotation, 'segmented')
    segmented.text = p_segmented

    fn = os.path.splitext(p_filename)[0]
    etree.write('xml/' + fn + '.xml')
